<script setup>
import { reactive, ref, onMounted, computed } from 'vue';
const dialogVisible = ref(false);
const form = ref({
  cate_name: '娱乐',
  cate_alias: 'yule'
});
const open = (obj) => {
  dialogVisible.value = true;
  form.value = obj;
};
defineProps({
  title: {
    type: String
  }
});
defineExpose({
  open
});
const rules = ref({
  cate_name: [
    { required: true, message: '请输入分类名称', trigger: 'blur' },
    {
      pattern: /^\S{1,10}$/,
      message: '分类名必须是1-10位的非空字符',
      trigger: 'blur'
    }
  ],
  cate_alias: [
    { required: true, message: '请输入分类别名', trigger: 'blur' },
    {
      pattern: /^[a-zA-Z0-9]{1,15}$/,
      message: '分类别名必须是1-15位的字母数字',
      trigger: 'blur'
    }
  ]
});
const emit = defineEmits(['success']);
const submit = () => {
  dialogVisible.value = false;
  emit('success');
};
</script>

<template>
  <el-dialog v-model="dialogVisible" :title="title" width="500">
    <el-form :rules="rules" :model="form">
      <el-form-item
        label="分类名称"
        :label-width="formLabelWidth"
        prop="cate_name"
      >
        <el-input
          placeholder="请输入名称"
          v-model="form.cate_name"
          :required="true"
          autocomplete="off"
        />
      </el-form-item>
      <el-form-item
        label="分类别名"
        prop="cate_alias"
        :label-width="formLabelWidth"
      >
        <el-input
          :required="true"
          placeholder="请输入别名"
          v-model="form.cate_alias"
          autocomplete="off"
        />
      </el-form-item>
    </el-form>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="dialogVisible = false">取消</el-button>
        <el-button type="primary" @click="submit"> 确认 </el-button>
      </div>
    </template>
  </el-dialog>
</template>

<style lang="scss" scoped>
.el-dialog {
  padding: 10px 20px;
  .el-form {
    margin: 0 40px;
  }
}
</style>
